import request from "@/utils/request";
export default {
  // 手机号密码登录
  // { mobile: string,password: string }
  login(params) {
    return request.post("public/login", params).then(_ => {
      return _.data;
    });
  },
  // 用户名登录
  // { uname: string,password: string }
  unameLogin(formData) {
    return request.post("public/unameLogin", formData).then(_ => {
      return _.data;
    });
  },
  // 快速登录
  // {mobile:number,code:number}
  fastLogin(params) {
    return request.post("public/fastLogin", params).then(_ => {
      return _.data;
    });
  },
  // 第三方登录 type qq  weixin sinaweibo
  oauthLogin(type, userinfo) {
    return request.post("oauth/login", {
      type,
      userinfo
    }).then(_ => {
      return _.data;
    });
  },
  // 注册
  // {mobile:string,password:string,code:number}
  register(params) {
    return request.post("public/register", params);
  },
  // 发送手机号验证码
  // {mobile:string}
  sendMobileVerifyCode(mobile) {
    return request.post("public/verifyCode", {
      mobile
    });
  },
  // 手机号是否可以登录
  mobileIsCanLogin(mobile) {
    return request.post("public/mobileExists", {
      mobile
    });
  },
  // 获取用户信息
  getUserInfo() {
    let params = {};
    // #ifdef APP-PLUS
    Object.assign(params, {
      clientId: plus.push.getClientInfo().clientid
    });
    // #endif
    return request.get("user/userInfo", params);
  },
  // 系统头像列表
  getSystemAvatars() {
    return request.get("public/avatars");
  },
  // 获取阳光值
  getSunshineValue() {
    return request.get("user/sunShine");
  },
  // 退出
  logout() {
    return request.get("user/logout");
  },
  // 销户
  logoff() {
    return request.post("user/delMe");
  },
  // 修改密码
  changePassword(oldPassword, newPassword) {
    return request.post("user/changePassword", {
      oldPassword,
      newPassword
    });
  },
  // 设置头像
  setAvatar(formData = {
    avatar
  }) {
    return request.post("user/setAvatar", formData);
  },
  // 修改昵称
  setNickName(formData = {
    nickName
  }) {
    return request.post("user/setNickName", formData);
  },
  // 设置性别
  setSex(formData = {
    sex
  }) {
    return request.post("user/setSex", formData);
  },
  setSignature(formData = {
    signature
  }) {
    return request.post("user/setSignature", formData);
  },
  // 获取省市区城市列表
  getCity(pid = 0) {
    return request.get("public/addr", {
      pid
    });
  },
  // 添加地址
  addAddress(formData) {
    return request.post("user/addrAdd", formData);
  },
  // 修改地址
  editAddress(formData) {
    return request.post("user/addrEdit", formData);
  },
  // 用户地址列表
  address() {
    return request.get("user/addrList");
  },
  // 地址详情
  addressDetail(id) {
    return request.post("user/addrDetail", {
      id
    });
  },
  // 删除地址
  delAddress(id) {
    return request.post("user/addrDel", {
      id
    });
  },
  // 获取用户设置
  getConfig() {
    return request.get("user/setting");
  },
  setConfig(name, value) {
    return request.post("user/setSetting", {
      name,
      value
    });
  }
};
